package com.charging.business.enums;

/**
 * ETC特殊车辆标识
 * 255 - 普通车
 * 0 - ETC大件运输
 * 1 - 不优惠
 * 2 - 绿通
 * 3 - 联合收割机
 */
public class Vsign {
    /**
     * 普通
     */
    public static final int NORMAL = 0xFF;

    /**
     * ETC大件运输
     */
    public static final int ETCLARGE = 0x00;

    /**
     * 绿通车
     */
    public static final int GREEN = 0x02;

    /**
     * 联合收割机
     */
    public static final int COMHV = 0x03;

    /**
     * 疫苗车
     */
    public static final int VACC = 0x05;

    /**
     * 抢险救灾车
     */
    public static final int QXJZ = 0x06;

    /**
     * 翻译特殊车辆标识
     */
    public static String trans(int vSign) {
        if (vSign == NORMAL) {
            return "普通车";
        }
        if (vSign == ETCLARGE) {
            return "大件运输车";
        }
        if (vSign == GREEN) {
            return "绿通车";
        }
        if (vSign == COMHV) {
            return "联合收割机";
        }
        if (vSign == VACC) {
            return "疫苗车";
        }
        if (vSign == QXJZ) {
            return "抢险救灾车";
        }

        return String.format("[%d]未知", vSign);
    }

    /**
     * 特殊车标识检测
     */
    public static boolean tstVSign(boolean bEntry, boolean bETC, int vtype, int vSign) {
        if (bEntry) {// 入口
            if (bETC) {// ETC
                if (Vtype.isTruck(vtype)) {// 为ETC货车
                    return isNumIn(vSign, NORMAL, ETCLARGE);
                } else {// 为ETC客车
                    return isNumIn(vSign, NORMAL);
                }
            } else {// MTC
                return isNumIn(vSign, NORMAL);
            }
        } else {// 出口
            if (bETC) {// ETC
                if (Vtype.isTruck(vtype)) {// 为ETC货车
                    return isNumIn(vSign, NORMAL, ETCLARGE, GREEN, COMHV);
                } else {// 为ETC客车
                    return isNumIn(vSign, NORMAL);
                }
            } else {// MTC
                return isNumIn(vSign, NORMAL);
            }
        }
    }

    public static String[] array() {
        return new String[]{"0:大件运输", "2:绿通车", "3:联合收割机", "255:普通车"};
    }

    /**
     * 车辆状态标识校验
     *
     * @param vehicleType - 车型
     * @param vehicleSign - 状态标识
     * @return
     */
    public static int chkVSign(int vehicleType, int vehicleSign) {
        int res = 0;
        if (vehicleType < 10) {
            res = 255;
        } else {
            if (tstVSign(vehicleSign)) {
                res = vehicleSign;
            } else {
                res = 255;
            }
        }

        return res;
    }

    /**
     * 车辆状态标识测试
     *
     * @param vehicleSign
     * @return  true : 正常   false : 不正常
     */
    public static boolean tstVSign(int vehicleSign) {
        return vehicleSign >= 0 && vehicleSign <= 255;
    }

    /**
     * 检查给定数是否是系列数之一
     */
    private static boolean isNumIn(int number, int... numbers) {
        for (int num : numbers) {
            if (number == num) {
                return true;
            }
        }
        return false;
    }

}
